<?php
namespace Admin\Controller;
use Admin\Common\CommonController;
use Common\Common\Tree;
/**
 * 文章问题分类管理
 */

class CategoryController extends CommonController{

    public function index(){
    	//f分类管理
    	$sql = "SELECT * FROM `category`";
    	$model = M('category');
    	$result = $model->query($sql);
    	// var_dump($result);
    	$tree = new Tree();

    	$result = $tree->index($result);

    	$this->assign('result', $result);
    	$this->display();
    }

    public function add()
    {
        if(IS_POST){
          
            $data['fid'] = I('post.id',0);
            $data['cname'] = I('post.cname');
            $model = M('category');
            $res = $model->add($data);
            if($res){
                $this->success('增加成功',U('Admin/Category/index'),1);
            }else{
                $this->error('增加失败',U('Admin/Category/index'),1);
            }
            
        }else{

            $this->error('非法请求',U('Admin/Category/index'),1);
        }
    }

}
?>